import { computed } from 'vue';
import { useUserContext } from '@/store/modules/user-context';

/**
 * 用于获取和使用 uniqueStr 的 composable 函数
 */
export function useUniqueStr() {
  const userContext = useUserContext();

  const uniqueStr = computed(() => userContext.getUniqueStr);

  // 生成带 ucenter 前缀的路径
  const getUcenterPath = (path: string) => {
    return `/ucenter/${uniqueStr.value}${path}`;
  };

  // 生成完整的 URL
  const getFullUrl = (path: string) => {
    return `${window.location.origin}/ucenter/${uniqueStr.value}${path}`;
  };

  return {
    uniqueStr,
    getUcenterPath,
    getFullUrl,
  };
}